package com.xyazm.order.domain.builder;


import com.xyazm.order.domain.dto.*;
import com.xyazm.order.domain.entity.AfterSaleInfoDO;
import com.xyazm.order.domain.entity.AfterSaleItemDO;
import com.xyazm.order.domain.entity.AfterSaleLogDO;
import com.xyazm.order.domain.entity.AfterSaleRefundDO;
import com.xyazm.order.mapstruct.OrderApiMapstruct;
import org.apache.commons.collections.CollectionUtils;

import java.util.List;

/**
 * <p>
 *  售后单详情构造器
 * </p>
 */
public class AfterSaleOrderDetailBuilder {

    private AfterSaleOrderDetailDTO detailDTO = new AfterSaleOrderDetailDTO();

    public AfterSaleOrderDetailBuilder afterSaleInfo(AfterSaleInfoDO afterSaleInfoDO) {
        if(null!= afterSaleInfoDO) {
            AfterSaleInfoDTO afterSaleInfoDTO = OrderApiMapstruct.INSTANCE.convertAfterSaleInfoDTO(afterSaleInfoDO);
            detailDTO.setAfterSaleInfo(afterSaleInfoDTO);
        }
        return this;
    }

    public AfterSaleOrderDetailBuilder afterSaleItems(List<AfterSaleItemDO> afterSaleItemDOS) {
        if(CollectionUtils.isNotEmpty(afterSaleItemDOS)) {
            List<AfterSaleItemDTO> afterSaleItemDTOList =
                    OrderApiMapstruct.INSTANCE.convertAfterSaleItemDTO(afterSaleItemDOS);
            detailDTO.setAfterSaleItems(afterSaleItemDTOList);
        }
        return this;
    }

    public AfterSaleOrderDetailBuilder afterSaleRefunds(List<AfterSaleRefundDO> afterSaleRefundDOS) {
        if(CollectionUtils.isNotEmpty(afterSaleRefundDOS)) {
            List<AfterSaleRefundDTO> afterSaleRefundDTOList =
                    OrderApiMapstruct.INSTANCE.convertAfterSaleRefundDTO(afterSaleRefundDOS);
            detailDTO.setAfterSaleRefunds(afterSaleRefundDTOList);
        }
        return this;
    }

    public AfterSaleOrderDetailBuilder afterSaleLogs(List<AfterSaleLogDO> afterSaleLogDOS) {
       if(CollectionUtils.isNotEmpty(afterSaleLogDOS)) {
           List<AfterSaleLogDTO> afterSaleLogsDTOList =
                   OrderApiMapstruct.INSTANCE.convertAfterSaleLogDTO(afterSaleLogDOS);
           detailDTO.setAfterSaleLogs(afterSaleLogsDTOList);
       }
       return this;
    }

    public AfterSaleOrderDetailDTO build() {
        return detailDTO;
    }
}
